package com.gzh.teaching.controller;

import com.gzh.core.dao.po.AcademyEntity;
import com.gzh.core.dao.po.ClassEntity;
import com.gzh.core.dao.po.UserEntity;
import com.gzh.core.model.vo.Result;
import com.gzh.core.service.CheckToken;
import com.gzh.core.util.RequestContextUtil;
import com.gzh.teaching.model.vo.QueryParam;
import com.gzh.teaching.model.vo.QueryUserParam;
import com.gzh.teaching.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author guanzh
 * @Date 2022/3/3 17:12
 * @Description
 */
@Slf4j
@RequestMapping("/v1/api/admin")
@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/queryAllUser")
    @CheckToken
    public ResponseEntity<?> queryAllUser(QueryUserParam param) {
        Integer userId = RequestContextUtil.getCurrentUserId();
        return Result.ok(adminService.queryAllUser(param.paramToIn(userId)));
    }

    @PostMapping("/deleteUser")
    @CheckToken
    public ResponseEntity<?> deleteUser(@RequestBody UserEntity user) {
        adminService.deleteUser(user.getUserId());
        return Result.ok();
    }

    @PostMapping("/editUser")
    @CheckToken
    public ResponseEntity<?> editUser(@RequestBody UserEntity user) {
        adminService.editUser(user);
        return Result.ok();
    }

    @GetMapping("/queryAcademy")
    @CheckToken
    public ResponseEntity<?> queryAcademy(QueryParam param) {
        Integer userId = RequestContextUtil.getCurrentUserId();
        return Result.ok(adminService.queryAcademy(param.paramToIn(userId)));
    }

    @GetMapping("/queryClass")
    @CheckToken
    public ResponseEntity<?> queryClass(QueryParam param) {
        Integer userId = RequestContextUtil.getCurrentUserId();
        return Result.ok(adminService.queryClass(param.paramToIn(userId)));
    }

    @PostMapping("/editInfo")
    @CheckToken
    public ResponseEntity<?> editInfo(@RequestBody QueryParam param) {
        Integer userId = RequestContextUtil.getCurrentUserId();
        adminService.editInfo(param.paramToIn(userId));
        return Result.ok();
    }

    @PostMapping("/insertAcademy")
    @CheckToken
    public ResponseEntity<?> insertAcademy(@RequestBody AcademyEntity param) {
        Integer userId = RequestContextUtil.getCurrentUserId();
        adminService.insertAcademy(param);
        return Result.ok();
    }

    @PostMapping("/insertClass")
    @CheckToken
    public ResponseEntity<?> insertClass(@RequestBody ClassEntity param) {
        Integer userId = RequestContextUtil.getCurrentUserId();
        adminService.insertClass(param);
        return Result.ok();
    }
}
